$(function(){
	//SetInputValue();

	//移除宿舍的管理权限
	dormitory_jurisdiction_del=function(table,uid){
		grade=$(table).parents("tr").find(".grade").html();
		major=$(table).parents("tr").find(".major_id").html();
		rooms=$(table).parents("tr").find(".rooms").html();

		if(rooms==0){
			layer.msg('宿舍管理数量为零，不需要移除', {
				time: 2000, //2s后自动关闭
			});
		}else{
			removeList=new Array();
			remove=new Object();
			remove.uid=uid;
			remove.grade=grade;
			remove.major=major;

			removeList[0]=remove;
			removeJSON=JSON.stringify(removeList);

			layer.confirm('确定移除？', {
				btn: ['确定','取消'] //按钮
			}, function(){
				$.post("/php/instructor-dormitory-management.php",{action:1,data:removeJSON},
				function(result){
					resultObj=JSON.parse(result);
					switch(resultObj.code){
						case '2001':
							layer.msg(resultObj.message, {icon: 1});
							break;
						case '2002':break;
						case '2003':break;
						case '2004':
							layer.msg(resultObj.message, {icon: 2});
							break;
						default:break;
					}
				});
			}, function(){
			});
		}
	}
	//移除宿舍的管理权限，多选
	dormitory_jurisdiction_del_checkbox=function(){
		removeList=new Array();
		$(":checkbox[name='users_checkbox']:checked").each(function(index,e){
			//alert($(this).prop("checked"));
			rooms=$(this).parents("tr").find(".rooms").html();
            if(rooms==0){
				$(this).prop("checked",false);
            }else{
				uid=$(this).val();
				grade=$(this).parents("tr").find(".grade").html();
				major=$(this).parents("tr").find(".major_id").html();
				rooms=$(this).parents("tr").find(".rooms").html();
				
				remove=new Object();
				remove.uid=uid;
				remove.grade=grade;
				remove.major=major;

				removeList[index]=remove;
            }
		});
		
		if(removeList.length>0){
			removeJSON=JSON.stringify(removeList);
			layer.confirm('确定移除？', {
				btn: ['确定','取消'] //按钮
			}, function(){
				$.post("/php/instructor-dormitory-management.php",{action:1,data:removeJSON},
				function(result){
					resultObj=JSON.parse(result);
					switch(resultObj.code){
						case '2001':
							layer.msg(resultObj.message,{icon: 1,btn:['确定']},function(){
								location.replace(location.href);
							});
							break;
						case '2002':break;
						case '2003':break;
						case '2004':
							layer.msg(resultObj.message, {icon: 2});
							break;
						default:break;
					}
				});
			}, function(){
			});
		}else{
			layer.msg('未选中任何项');
		}
		
	}
    //获取url参数
	function GetQueryString(name){
		var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r!=null)return unescape(r[2]); return null;
    }
    //设置输入框的值
	/*function SetInputValue(){
		var pattern=GetQueryString("pattern");
        var major=GetQueryString("major");
        var grade=GetQueryString("grade");
        var search=GetQueryString("search");
		if(pattern !=null && pattern.toString().length>=1){
			$("#pattern_select").val(pattern);
        }
        if(major !=null && major.toString().length>=1){
			$("#major_select").val(major);
        }
        if(grade !=null && grade.toString().length>=1){
			$("#grade_select").val(grade);
		}
		if(search !=null && search.toString().length>=1){
			$("#search").val(search);
		}
	}*/
	
	//跳页
    $("select").change(function(){
		
		var pattern=GetQueryString("pattern");
		var major=GetQueryString("major");
        var grade=GetQueryString("grade");
		var search=GetQueryString("search");
		if(pattern ==null || pattern==''){
			pattern=0;
        }
        if(major ==null || major==''){
			major=0;
        }
        if(grade ==null || grade==''){
			grade=0;
		}
		if(search ==null){
			search='';
		}
		var id=$(this).attr("id");
		switch(id){
			case 'dormitory_page':
                url="./instructor-dormitory-management.php?status="+status+"&major="+major
                +"&grade="+grade+"&page="+$(this).val()+"&search="+search;
				window.location.href=url;
			break;
			default:break;
		}
	});
});